'''------------
登录DX平台
在个人中心修改账号名
退出登录
------------'''
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import random

usrname = '13980617516'
pasword = '10000'
newname = random.choice('王孟赵李杜张夏孙刘欧杨')+'医生'

driver = webdriver.Chrome()
driver.maximize_window()
#登录
driver.get('https://dxt.yayi360.com/#/')
driver.find_element(By.XPATH, '//div[@placeholder="请输入手机号"]/input').send_keys(usrname)
driver.find_element(By.XPATH, '//div[@placeholder="请输入密码"]/input').send_keys(pasword)
driver.find_element(By.CLASS_NAME, 'zh_postForm').click()
time.sleep(5)
if driver.current_url == 'https://dxt.yayi360.com/#/indexDoc':
    print('登录成功')
else:
    print('登录失败')
#进入个人中心，修改用户名
driver.find_element(By.CLASS_NAME, "yg-dropdown-link").click()
driver.find_elements_by_class_name("yg-dropdown-menu__item")[0].click()#选择个人中心
driver.find_element(By.XPATH, '//div[@class="posi"]/button/span').click()
driver.find_element(By.XPATH, '//*[@for="username"]/..//div/input').clear()
driver.find_element(By.XPATH, '//*[@for="username"]/..//div/input').send_keys(newname)#修改用户名
driver.find_element(By.XPATH, '//*[@id="app"]/div[2]/div[2]/div/div/div[5]/div/div[3]/input[1]').click()
time.sleep(5)
#退出登录
driver.find_element(By.CLASS_NAME, "yg-dropdown-link").click()
driver.find_elements_by_class_name("yg-dropdown-menu__item")[3].click()#选择退出登录
driver.find_element(By.XPATH, '//div[@id="yg_msgbox_dom"]/div/div[3]/input').click()
time.sleep(5)
if driver.current_url == 'https://dxt.yayi360.com/#/':
    print('退出成功')
else:
    print('退出失败')
driver.quit()